<template>
  <div>
    <div style="display: flex;justify-content: center;margin-top: 30px">
      <el-card style="width: 80%;margin: 10px">
        <div style="display: flex;border-bottom: 2px solid #8c8c8c">
          <div style="flex: 1;height: 50px;font-size: 25px">用户 <span
              style="color: #409EFF">{{ userName }}</span> 的收藏
          </div>
          <div style="height: 50px;font-size: 25px;flex: 1">
            <el-input style="width: 200px;margin: 0 15px" placeholder="请输入用户账户" v-model="user_name" type="number"
                      min="0" :controls="false"></el-input>
            <el-button type="primary" size="medium" @click="load()" style="height: 40px">查询</el-button>
          </div>
        </div>
        <div style="display: flex;align-items: center;justify-content: center;margin-top: 10px">
          <div style="flex: 1">
            <div style="margin-top: 20px">
            </div>
          </div>
        </div>
      </el-card>
    </div>
    <div style="display: flex;justify-content: center">
      <el-card style="width: 80%;margin: 10px">
        <div style="height: 50px;font-size: 25px">用户收藏</div>
        <div style="margin-bottom: 10px">
        </div>
        <el-table ref="shopsTable" :data="tableData" stripe
                  :header-cell-style="{backgroundColor:'aliceblue',color:'#666'}">
          <el-table-column prop="hotel_id" label="酒店id" align="center"></el-table-column>
          <el-table-column prop="url" label="图片">
            <template v-slot="scope">
              <div style="display: flex;align-items: center">
                <el-image style="width: 50px;height: 50px;border-radius: 50%" v-if="scope.row.hotel_id"
                          :src="`http://localhost:8000/hotel_image_download/${scope.row.hotel_id}`"
                          :preview-src-list="[scope.row.hotel_id]"></el-image>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="hotel_name" label="酒店名称"></el-table-column>
          <el-table-column prop="level" label="酒店级别"></el-table-column>
          <el-table-column prop="location" label="酒店地址"></el-table-column>
          <el-table-column prop="intro" label="酒店简介" width="400px" align="center"></el-table-column>
        </el-table>
        <div style="margin: 10px 0">
          <el-pagination
              @current-change="handleCurrentChange"
              :current-page="pageNum"
              :page-sizes="[100, 200, 300, 400]"
              :page-size="pageSize"
              layout="total,  prev, pager, next"
              :total="total">
          </el-pagination>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: "userSaves",
  data() {
    return {
      tableData: [], //表中数据
      pageNum: 1,
      pageSize: 5,
      total: 0,
      user_name: "",
      userName: "",
      hotel_name: "",
    }
  },
  created() {
    this.load();
  },
  methods: {
    load(pageNum) {  //分页查询
      if (pageNum) this.pageNum = pageNum
      this.$request.post('/user_collection_list/', {
        "username": this.user_name,
        "page_size": this.pageSize,
        "page_id": this.pageNum,
        "hotel_name": this.hotel_name,
      }).then(res => {
        if (res.code === '200') {
          this.tableData = res.data.collection_list
          this.total = res.data.item_amount
          if (res.msg === "查询成功") {
            this.$message.success(res.msg)
            this.userName = this.user_name
          }else {
            this.$message.warning("找不到该用户")
          }
        } else {
            this.$message.warning("找不到该用户")
        }
      })
    },
    handleCurrentChange(pageNum) {
      this.load(pageNum)
    }
    ,
  }
}
</script>
<style scoped>
/deep/ input::-webkit-outer-spin-button,
/deep/ input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

/deep/ input[type="number"] {
  -moz-appearance: textfield;
}

/deep/ inpit {
  border: none
}
</style>